$(document).ready(function(){
	
	setInterval(function(){
			
			$.ajax({
		  url: '/ProjetWebEAR/ChatServlet?action=update&caller='+$('#caller').val()+'&called='+$('#called').val()+'',
		  success: function(data, textStatus, jqXHR){
			  $('#messages ul').html(data);
		  }
		});
	}, 2000);
	
	$("#message").keyup(
			function(e){
                console.log(e.keyCode);
                switch(e.keyCode)
                {
                    case 13: if($('#text').val().length > 0)$('#send').trigger('click');
                        break;
                }   
			return false;
		}
	);
	
	$('#send').click(function(){
		console.log('click triggered');
		$.post("/ProjetWebEAR/ChatServlet", $("#chatform").serialize());
		$("#text").val('');
		return false;
	});
	
});